const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tuisong: '已关闭'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSetting({
      withSubscriptions: true,
      success(r) {
        if (r.subscriptionsSetting.mainSwitch) {
          that.setData({
            tuisong: '已开启'
          })
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  dingyue: function () {
    var that = this;
    wx.requestSubscribeMessage({
      tmplIds: ['z5dASgSZjyLPjj0uKKRFZ0fpTZBj3bC36EB3jsRKpGw'],
      complete: function (res) {
        console.log(res)
        if (res.z5dASgSZjyLPjj0uKKRFZ0fpTZBj3bC36EB3jsRKpGw == 'accept') {
          console.log('已开启')
          that.setData({
            tuisong: '已开启'
          })
        } else {
          console.log('已关闭')
          that.setData({
            tuisong: '已关闭'
          })
        }

      }
    })
  },
  tochangepass: function () {
    wx.navigateTo({
      url: 'changepass'
    })
  },
  yijianfankui: function () {
    wx.navigateTo({
      url: 'yijianfankui'
    })
  },
  qinghuancun: function(){
   let str = `${wx.getStorageSync('FjLoginLog').UID}+7CC9E12ACD07CFDC5C3DDD10E7D0A1CF+feijiuapp+${app.getCurrentDate()}`
   let aerstr = app.aesAdd(str, 'feijiuwapwangxin', '6010140320331210')

   let urls = `${app.data.jp_api_web_url}logoff/index.aspx?utoken=${aerstr}`
    wx.navigateTo({
      url: `../other/publicWeb`,
      success: function (res) {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('publicData', {
          url: urls
        })
      }
    })
  },

  


  logout: function () {
    wx.showModal({
      title: 'Feijiu网提示您!',
      content: '是否要退出登录',
      showCancel: true,
      cancelText: '取消',
      cancelColor: '#000000',
      confirmText: '确定',
      confirmColor: '#3CC51F',
      success: (res) => {
        if (res.confirm) {
          // wx.clearStorageSync();
          wx.removeStorageSync('openid')
          wx.removeStorageSync('sbtype')
          wx.removeStorageSync('sbname')
          wx.removeStorageSync('ip')
          wx.removeStorageSync('is_Yins')
          wx.removeStorageSync('FjLoginLog')
          var pages = getCurrentPages();
          var prevPage = pages[pages.length - 2];
          prevPage.setData({
            logout: false,
            loginbtn: true,
            usernaemstatus: false,
            headpic: '../../images/indexIcon/headerpic.png',
          })
          setTimeout(function () {
            wx.navigateBack()
          }, 1000)
        }
      },
      fail: (res) => {

      },
      complete: (res) => {

      }
    })
  },
  tothreelogin: function () {
    wx.navigateTo({
      url: 'threelogin'
    })
  },
})
